package com.android.qjpmc.application_module.activity;

import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.android.qjpmc.R;
import com.android.qjpmc.application_module.pop.ListCheckPopupWindow;
import com.android.qjpmc.bean.ListCheckPopBean;
import com.android.qjpmc.databinding.ActivityUserInformationBinding;
import com.android.qjpmc.manager.IntentManager;
import com.android.qjpmc.widget.base.BaseCommonActivity;
import com.android.qjpmc.widget.manager.HttpsManager;
import com.android.qjpmc.widget.manager.SPManager;
import com.android.qjpmc.widget.mvvm.view.AppActivityManager;
import com.android.qjpmc.widget.retrofithelper.http.Url;

import java.util.ArrayList;
import java.util.List;

import androidx.fragment.app.FragmentActivity;

public class UserReloginActivity extends BaseCommonActivity<ActivityUserInformationBinding> {
    @Override
    public int getLayoutId() {
        return R.layout.activity_user_information;
    }

    @Override
    public void initView() {
        super.initView();
        mBinding.setView(this);
        String loginInfo = SPManager.LoginInfo.getLoginInfo();
        mBinding.tvUserName.setText("用户名：" + loginInfo);
    }

    public void onLoginOut() {
        SPManager.LoginInfo.saveLoginInfo("");
        AppActivityManager.getAppActivityManager().finishAllActivity();
        IntentManager.toLoginActivity(this);
    }

    private ListCheckPopupWindow queryApiPopupWindow;

    public void onSwitchApi() {
        HttpsManager.onSwitchApi(this);
      /*  ListCheckPopBean selectApiType = new ListCheckPopBean();

        selectApiType.id = Url.BASE_URL;
        if (Url.BASE_URL.contains("59.36.165.191")) {
            selectApiType.name = "测试环境";
        } else if (Url.BASE_URL.contains("110.53.191.186")) {
            selectApiType.name = "正式环境";
        }
        if (queryApiPopupWindow == null) {
            queryApiPopupWindow = new ListCheckPopupWindow((FragmentActivity) this);
            List<ListCheckPopBean> popListData = new ArrayList<>();
            popListData.add(new ListCheckPopBean("http://59.36.165.191:8085/", "测试环境", selectApiType.name.equals("测试环境")));
            popListData.add(new ListCheckPopBean("http://110.53.191.186:8085/", "正式环境", selectApiType.name.equals("正式环境")));
            queryApiPopupWindow.initListData(popListData);
            queryApiPopupWindow.setListCheckPopupWindowListener(new ListCheckPopupWindow.ListCheckPopupWindowListener() {
                @Override
                public void onPopChooseResult(List<ListCheckPopBean> popListData) {
                    ListCheckPopBean popListDatumTemp = null;
                    for (ListCheckPopBean popListDatum : popListData) {
                        if (popListDatum.isOpen) {
                            popListDatumTemp = popListDatum;
                            break;
                        }
                    }
                    if (popListDatumTemp == null) {
                        return;
                    }
                    SPManager.BaseUrlConfigData.setBaseUrl(popListDatumTemp.id);
                    final Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName());
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);

                    //杀掉以前进程
                    android.os.Process.killProcess(android.os.Process.myPid());

                }
            });
        }
        View view = getWindow().getDecorView();
        queryApiPopupWindow.showPopupWindowAtLocation(view);

*/
    }
}
